package com.pentakill.mo.auth.user.business.ebo;

import java.io.Serializable;
import java.util.List;
import java.util.Set;

import com.pentakill.mo.auth.role.business.ebi.RoleEbi;
import com.pentakill.mo.auth.role.vo.RoleModel;
import com.pentakill.mo.auth.user.business.ebi.UserEbi;
import com.pentakill.mo.auth.user.dao.dao.UserDao;
import com.pentakill.mo.auth.user.vo.UserModel;
import com.pentakill.mo.util.base.BaseQueryModel;
import com.pentakill.mo.util.exception.AppException;
import com.pentakill.mo.util.format.MD5Utils;

public class UserEbo implements UserEbi{
	//注入userDao
	private UserDao userDao;
	//注入角色roleEbi
	private RoleEbi roleEbi;
	
	

	public void setRoleEbi(RoleEbi roleEbi) {
		this.roleEbi = roleEbi;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	public void save(UserModel t) {
		// TODO Auto-generated method stub
		
	}

	public List<UserModel> getAll() {
		// TODO Auto-generated method stub
		return null;
	}

	public UserModel get(Serializable uuid) {
		// TODO Auto-generated method stub
		return null;
	}

	public void update(UserModel t) {
		// TODO Auto-generated method stub
		
	}

	public void delete(UserModel t) {
		// TODO Auto-generated method stub
		
	}

	public List<UserModel> getAll(BaseQueryModel dqm, Integer pageNum, Integer pageCount) {
		// TODO Auto-generated method stub
		return null;
	}

	public Integer getCount(BaseQueryModel dqm) {
		// TODO Auto-generated method stub
		return null;
	}
	
	
	//登录
	public boolean userByN_P(UserModel user) {
		if (user == null) {
			throw new AppException();
		}
		user.setPassword(MD5Utils.md5(user.getPassword()));
		return userDao.userByN_P(user);
	}
	
	
	//注册
	public void userByRegister(UserModel user) {
		//验证
		if (user == null) {
			throw new AppException("用户错误");
		}
		//加密算法
		user.setPassword(MD5Utils.md5(user.getPassword().toString()));
		
		//赋予普通权限(plain)
		String role = "普通用户";
		Set<RoleModel> roleModels =  roleEbi.getName(role);
		user.setRoleModels(roleModels);
		userDao.add(user);
	}

	public void ACByRegister(UserModel user) {
		//验证
		if (user == null) {
			throw new AppException("用户错误");
		}
		//加密算法
		user.setPassword(MD5Utils.md5(user.getPassword().toString()));
		userDao.add(user);
	}

	
	
}
